﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace HAL9006.Terminal
{
    public class CommandMap
    {
        public Dictionary<string, ITerminalCommand> Commands { get; set; }

        public CommandMap() {
            Commands = new Dictionary<string, ITerminalCommand>();
            Commands.Add("theme", new ThemeCommand());
        }

        public string Execute(string command) {
            if (string.IsNullOrWhiteSpace(command)) {
                return string.Empty;
            }

            var commandParts = command.Split(' ');
            if (commandParts.Count() >= 1 && Commands.ContainsKey(commandParts[0]))
            {
                var terminalCommand = Commands[commandParts[0]];
                string[] parameters = commandParts.Skip(1).ToArray();
                return terminalCommand.Execute(parameters);
            }

            return string.Empty;
        }
    }
}
